home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-17 | 16.6 KB | 629 lines | [TEXT/CWIE] |
-
-
- #include <iostream.h>
- #include <stdlib.h>
-
-
- #include "lotto.h"
- #include "lotto_calc_class.h"
-
-
-
-
- class lotto_calc *calc;
- lotto_struct *temp[MAX_STRUCTS];
-
- void main( void )
- {
- calc = new lotto_calc;
- bool quit = false;
- int choice;
- bool exists = false;
-
- do {
-
- choice = 0;
-
- print_main_menu();
-
- cout << "Choice?: ";
-
- cin >> choice;
- cout << endl << endl;
- switch( choice )
- {
- case 1:
- {
- // check if the file exists, and if so, if the user
- // wants to over-write it. default is true if no file exists.
- if( (check_file()) == true )
- {
- cout << "Start with the most recent draw and end with the oldest draw" << endl;
- cout << "Recommended: don't use any draws before 11/27/91 as the oldest draw" << endl;
- cout << "Enter numbers in the form <number> <dot> <number>" << endl;
- cout << "Example: 12.17.23.34.42.50" << endl;
- cout << "Then enter the date (Example: 11/27/91) with slashes" << endl;
- cout << "Enter a q to quit!" << endl << endl;
-
-
- // init the class vars
- calc->number_of_records = 0; // we are writing a new database
- calc->clear_user_input();
-
- bool run = true;
-
- do {
- cout << "Set?: ";
- cin >> calc->user_input;
- run = ( calc->set_struct_file() );
- cout << endl;
-
- if( run == true )
- {
- cout << "Date?: ";
- cin >> calc->record[calc->number_of_records - 1]->date;
- }
- cout << endl;
-
- if( run == true )
- {
- cout << "Set # " << calc->number_of_records << " is: ";
- for( int index = 0; index < 6; index++ )
- {
- cout << calc->record[calc->number_of_records - 1]->set[index] << ' ';
- }
- cout << endl;
- cout << "Date: " << calc->record[calc->number_of_records - 1]->date;
- cout << endl << endl;
- }
-
- } while( run == true );
-
- if( (calc->save_whole_file()) == true )
- {
- cout << "Data Saved To Disk!" << endl;
- break;
- } else {
- cout << "Error: No Data Written To Disk!!" << endl;
- break;
- }
- } else {
- cout << "No File Written." << endl <<endl;
- break;
- }
- break;
- }
-
- case 2:
- {
- int answer = 0;
-
- if( calc->read_file() == false )
- {
- cout << "Error: can not read file!" << endl;
- } else {
- cout << "You have " << (calc->number_of_records);
- cout << " records." << endl;
- cout << endl;
-
- do {
- cout << "View Which Record? <[ " << calc->number_of_records << " ]> ( 0 to quit ): ";
- cin >> answer;
- cout << endl;
- if( answer > (calc->number_of_records) )
- {
- cout << "That record doesn't exist!" << endl;
- cout << "try again: ";
- cin >> answer;
- cout << endl;
- }
- if( answer == 0 )
- {
- goto theEnd;
- }
-
- cout << "Set # " << answer << " is: ";
- for( int index = 0; index < 6; index++ )
- {
- cout << calc->record[answer - 1]->set[index] << ' ';
- }
- cout << endl;
- cout << "Reds: " << calc->record[answer - 1]->reds << " ";
- cout << "Whites: " << calc->record[answer - 1]->whites << " ";
- cout << "Blues: " << calc->record[answer - 1]->blues << " ";
- cout << endl;
- cout << "Odds: " << calc->record[answer - 1]->odds << " ";
- cout << "Evens: " << calc->record[answer - 1]->evens << " ";
- cout << endl;
- cout << "Date: " << calc->record[answer - 1]->date;
- cout << endl << endl;
- } while( answer != 0 );
-
- theEnd:
-
- if( answer == 0 )
- {
- calc->number_of_records = 0;
- calc->clear_records();
- break;
- }
- }
- calc->number_of_records = 0;
- calc->clear_records();
- break;
- }
-
- case 3:
- {
- /***************************************************************************
- this code is intended for allowing user to choose how many numbers to
- generate. At this time, more than ten chokes the program.
-
- int the_amount = 0;
-
- cout << endl;
- cout << "Generate How Many Numbers? ( 0 for default of 10 ): ";
- cin >> how_many;
-
- if( how_many > 0 )
- {
- the_amount = how_many;
- } else {
- the_amount = MAX_GEN;
- }
- ****************************************************************************/
- int set_predict[6] = {NULL};
- int how_many = 0;
- cout << endl << "Be patient! ... processing data" << endl;
- if( (calc->make_numbers( how_many )) == false )
- {
- cout << "Error: not enough data in database!" << endl;
- break;
- } else {
- cout << endl << endl;
- for( int index = 0; index < MAX_GEN; index++ )
- {
- cout << "Set # " << (index + 1) << " is ";
- for( int index2 = 0; index2 < 6; index2++ )
- {
- cout << calc->array10[index]->set[index2] << ' ';
- }
- cout << endl;
- cout << "Reds " << calc->array10[index]->reds << " ";
- cout << "Whites " << calc->array10[index]->whites << " ";
- cout << "Blues " << calc->array10[index]->blues << endl;
- cout << "Odds " << calc->array10[index]->odds << " ";
- cout << "Evens " << calc->array10[index]->evens << endl;
- cout << "Numbers due to be drawn soon: ";
- for( int index3 = 0; index3 < 6; index3++ )
- {
- if( calc->array10[index]->distrib[index3] == 1 )
- {
- cout << calc->array10[index]->set[index3] << ' ';
- }
- }
- cout << endl;
- cout << "Protected numbers: ";
- for(int index4 = 0; index4 < 6; index4++ )
- {
- if( calc->array10[index]->protect[index4] == 1 )
- {
- cout << calc->array10[index]->set[index4] << ' ';
- }
- }
- cout << endl << endl;
- }
- cout << "A protected number is either a member of a hot pair, or" << endl;
- cout << "a likely number to come up in the next draw." << endl;
- cout << "In order to get a good set, some of these numbers may have" << endl;
- cout << "to be changed, so the protection is removed." << endl << endl;
- cout << "The statistics for the last draw:" << endl;
- calc->read_file();
- cout << "Odds: " << calc->record[0]->odds;
- cout << " " << "Evens: " << calc->record[0]->evens;
- cout << " " << "Reds: " << calc->record[0]->reds;
- cout << " " << "Whites: " << calc->record[0]->whites;
- cout << " " << "Blues: " << calc->record[0]->blues;
- cout << endl << endl;
-
- cout << "Bonus substitution set: ";
- calc->p_set = new a_set;
- while( (calc->predict_set()) == false
- || calc->p_set->the_set[0] == 0 ){;}
- for( int i = 0; i < 6; i++ )
- {
- cout << calc->p_set->the_set[i] << ' ';
- }
- delete( calc->p_set );
- cout << endl << endl;
-
- cout << "Hot pairs used for this number generation: " << endl;
- for( int x1 = 0; x1 < 10; x1++ )
- {
- cout << "Pair # ";
- if( x1 < 9 )
- {
- cout << ' ';
- }
- cout << (x1 + 1) << " is: ";
- if( calc->ten_hot_pairs[x1][0] < 10 )
- {
- cout << ' ';
- }
- cout << calc->ten_hot_pairs[x1][0] << ' ';
- if( calc->ten_hot_pairs[x1][1] < 10 )
- {
- cout << ' ';
- }
- cout << calc->ten_hot_pairs[x1][1] << endl;
- }
- cout << endl << endl;
- cout << "Your ten number sets are: " << endl;
- for( int print = 0; print < MAX_GEN; print++ )
- {
- for( int print2 = 0; print2 < 6; print2++ )
- {
- if( calc->array10[print]->set[print2] < 10 )
- {
- cout << ' ';
- }
- cout << calc->array10[print]->set[print2] << ' ';
- }
- cout << endl;
- delete( calc->array10[print] );
- }
- cout << "Scroll up the window for the statistics on these numbers!";
- cout << endl << endl;
- calc->clear_records();
- }
- break;
- }
-
- case 4:
- {
- // check if the file exists, and if so, if the user
- // wants to over-write it. default is true if no file exists.
- if( (calc->check_for_file()) == true )
- {
- cout << "Updating Database!" << endl;
- cout << "Begin with the oldest draw, working up to the most recent" << endl;
- cout << "Enter numbers in the form <number> <dot> <number>" << endl;
- cout << "Example: 12.17.23.34.42.50" << endl;
- cout << "Then enter the date (Example: 11/27/91) with slashes" << endl;
- cout << "Enter a q ( on line -> Set?: ) to quit!" <<endl << endl;
-
-
- // init the class vars
- calc->clear_user_input();
-
- bool run = true;
-
- if( calc->read_file() == true )
- {
- do {
- cout << "Set?: ";
- cin >> calc->user_input;
- run = ( calc->update_struct_file() );
- cout << endl;
-
- if( run == true )
- {
- cout << "Date?: ";
- cin >> calc->record[0]->date;
- for( int indx = 0; indx < 20; indx++ )
- {
- if( (calc->record[0]->date[indx] == 'q') ||
- (calc->record[0]->date[indx] == 'Q') )
- {
- run = false;
- calc->clear_records();
- break;
- }
- }
-
- }
- cout << endl;
-
- if( run == true )
- {
- cout << "Set # " << 1 << " is: ";
- for( int index = 0; index < 6; index++ )
- {
- cout << calc->record[0]->set[index] << ' ';
- }
- cout << endl;
- cout << "Date: " << calc->record[0]->date;
- cout << endl << endl;
- }
-
- } while( run == true );
-
- if( (calc->save_whole_file()) == true )
- {
- cout << "Update Successful!" << endl;
- calc->clear_records();
- break;
- } else {
- calc->clear_records();
- cout << "Error: No Data Written To Disk!!" << endl;
- break;
- }
- } else {
- cout << "No File Exists!!" << endl;
- break;
- }
- break;
- }
- }
-
- case 5:
- {
- // check if the file exists, and if so, if the user
- // wants to over-write it. default is true if no file exists.
- if( (calc->check_for_file()) == true )
- {
- cout << "Editing Database!" << endl << endl;
- cout << "Enter the record number to begin editing (0 for default): ";
- cin >> calc->user_request;
- cout << endl << endl;
- cout << "Enter numbers in the form <number> <dot> <number>" << endl;
- cout << "Example: 12.17.23.34.42.50" << endl;
- cout << "Then enter the date (Example: 11/27/91) with slashes" << endl;
- cout << "Enter a q ( on line -> Set?: ) to quit!" <<endl << endl;
-
-
- // init the class vars
- calc->clear_user_input();
-
- bool run = true;
-
- if( calc->read_file() == true )
- {
- if( calc->user_request == 0 )
- {
- calc->user_request = (calc->number_of_records + 1);
- cout << "Begin adding sets with set# " << calc->user_request << endl << endl;
- }
-
- do {
-
- cout << "Set?: ";
- cin >> calc->user_input;
- run = ( calc->edit_struct_file() );
- cout << endl;
-
- if( run == true )
- {
- cout << "Date?: ";
- cin >> calc->record[(calc->user_request - 1)]->date;
- for( int indx = 0; indx < 20; indx++ )
- {
- if( (calc->record[(calc->user_request - 1)]->date[indx] == 'q') ||
- (calc->record[(calc->user_request - 1)]->date[indx] == 'Q') )
- {
- run = false;
- calc->clear_records();
- break;
- }
- }
-
- }
- cout << endl;
-
- if( run == true )
- {
- cout << "Set # " << (calc->user_request) << " is: ";
- for( int index = 0; index < 6; index++ )
- {
- cout << calc->record[(calc->user_request - 1)]->set[index] << ' ';
- }
- cout << endl;
- cout << "Date: " << calc->record[(calc->user_request - 1)]->date;
- cout << endl << endl;
- }
- calc->user_request++;
-
- } while( run == true );
-
- if( (calc->save_whole_file()) == true )
- {
- cout << "Update Successful!" << endl;
- calc->clear_records();
- break;
- } else {
- calc->clear_records();
- cout << "Error: No Data Written To Disk!!" << endl;
- break;
- }
- } else {
- cout << "No File Exists!!" << endl;
- break;
- }
- break;
- }
- }
-
- case 6:
- {
- if( calc->read_file() == false ) { cout << "Error: can't open file!" << endl; }
- int which_record = 0;
- cout << endl;
- cout << "Delete Records starting from?: ";
- cin >> which_record;
- calc->number_of_records = which_record;
- cout << endl <<endl;
- if( calc->save_whole_file() == false )
- {
- cout << "Error: can't save file!" << endl;
- } else {
- cout << "Data saved to disk!" << endl << endl;
- calc->clear_records();
- }
- break;
- }
-
- case 7:
- {
- int which_one = 0;
- calc->clear_user_input();
- if( calc->read_file() == false )
- {
- cout << "Error: can't read file!" << endl;
- break;
- }
- cout << "Delete Which Record?: ";
- cin >> which_one;
- cout << endl;
- for( int pass1 = 0; pass1 < calc->number_of_records; pass1++ )
- {
- if( pass1 == (which_one - 1) )
- {
- pass1++;
- }
- if( pass1 < (which_one - 1) )
- {
- temp[pass1] = calc->record[pass1];
- }
- if( pass1 > (which_one - 1) )
- {
- temp[pass1 - 1] = calc->record[pass1];
- }
- }
-
- calc->number_of_records--;
-
- for( int pass2 = 0; pass2 < calc->number_of_records; pass2++ )
- {
- calc->record[pass2] = temp[pass2];
- }
-
- calc->simple_save();
- calc->clear_records();
- cout << endl << "Finished!" << endl << endl;
- break;
- }
-
- case 8:
- {
- int which = 0;
- calc->clear_user_input();
- if(calc->read_file() == false )
- {
- cout << "Error: can't open file!" << endl;
- break;
- }
- cout << "Enter number of record to change: ";
- cin >> which;
- cout << endl;
- for( int pass = 0; pass < 6; pass++ )
- {
- cout << "Set # " << which << " number: " << (pass + 1) << " = ";
- cin >> temp[which - 1]->set[pass];
- cout << endl;
- }
- cout << "Set # " << which << " date = ";
- cin >> temp[which - 1]->date;
- cout << endl;
- cout << "Finished!" << endl << endl;
- for( int pass1 = 0; pass1 <= calc->number_of_records; pass1++ )
- {
- if( pass1 == (which - 1) )
- {
- pass1++;
- }
- if( pass1 < (which - 1) )
- {
- temp[pass1] = calc->record[pass1];
- }
- if( pass1 > (which - 1) )
- {
- temp[pass1] = calc->record[pass1 - 1];
- }
- }
-
- calc->number_of_records++;
-
- for( int pass2 = 0; pass2 < calc->number_of_records; pass2++ )
- {
- calc->record[pass2] = temp[pass2];
- }
-
- calc->simple_save();
- calc->clear_records();
- break;
- }
-
- case 9: { quit = true; }
-
- default: { break; }
- }
-
- } while( quit == false || quit != true );
- delete( calc );
- exit( 0 );
- }
-
- void print_main_menu( void )
- {
- cout << "Choose one of the following: " << endl << endl;
- cout << "1 for new database (completely erase data and begin new)" << endl;
- cout << "2 to view database" << endl;
- cout << "3 to generate numbers" << endl;
- cout << "4 to enter last numbers drawn (starts at beginning of database)" << endl;
- cout << "5 to enter more sets (starts at the end of database)" << endl;
- cout << "6 to delete records (cuts database off after selected number)" << endl;
- cout << "7 to delete a single record" << endl;
- cout << "8 to insert a single record" << endl;
- cout << "9 to quit" << endl;
-
- cout << endl << endl;
- }
-
- bool check_for_quit( char *an_array, int size )
- {
- // cycle through the string to look for a 'q'
- for( int index = 0; index < size; index++ )
- {
- if( (an_array[size] == 'q') || (an_array[size] == 'Q') )
- {
- return true; // true if the user wants to quit
- }
- }
- return false; // false if the user wishes to continue
- }
-
- bool check_file( void )
- {
- // checks if the file exists, and if so, if the user
- // wants to over-write it. default is true if no file exists
- bool write_data = true;
- char answer = NULL;
-
- if( (calc->check_for_file()) == true )
- {
- do {
- cout << "File Exists!!!!" << endl;
- cout << "Over-Write Existing File ?? ( y or n ): ";
- cin >> answer;
- cout << endl;
- switch( answer )
- {
- case 'y': case 'Y':
- {
- break;
- }
- case 'n': case 'N':
- {
- write_data = false;
- break;
- }
- default:
- {
- cout << "That is not one of the choices!" << endl << endl;
- answer = NULL;
- }
- }
- } while( answer == NULL );
- }
- return write_data;
- }